﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace MusicPlayer
{
    class ModifierAddFiles : ModifierPlayList
    {

        public override void DoOperation(List<Song> list)
        {
            AddFilesButton(list);
        }

        /// <summary>
        /// milena - functionality for selecting new files and checking for proper file format
        /// if the format is not recognized (we support only wav and mp3, an exception is thrown)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddFilesButton(List<Song> list)
        {
            // Create OpenFileDialog 

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();



            // Set filter for file extension and default file extension 
            dlg.Multiselect = true;
            dlg.DefaultExt = ".mp3";

            dlg.Filter = "MPEG Layer3 Files (*.mp3)|*.mp3|PCM Files (*.wav)|*.wav|Windows Media Audio Files (*.wma)|*.wma";



            // Display OpenFileDialog by calling ShowDialog method 

            Nullable<bool> result = dlg.ShowDialog();



            // Get the selected file name and display in a TextBox 

            if (result == true)
            {
                // because we allowed a filter for all files (*.*), 
                // a user can select files that are not media recognized by our program
                // so we iterate thru the selected files and check for such unrecognized files
                // if a file is found that is with different extension from wav or mp3 - we throw exception

                string[] slectedFilenames = dlg.FileNames;

                foreach (string s in slectedFilenames)
                {
                    //if (!s.ToLower().EndsWith(".wav") && !s.ToLower().EndsWith(".mp3"))
                    //{
                    //    throw new FormatNotSupportedException("There are selected files with format still not supported by our MusicPlayer", null);
                    //}
                    //// Dilyana: Adding the selected files to the playlist.
                    //else
                    //{
                    list.Add(new Song(@s));
                    //}
                }

                // if we get here, so everything with the selected files is ok and we can proceed to add them into the playlist

                // TODO - link with PlayList.cs -> add to songList

            }
        }
    }
}
